using UnityEngine;
using UnityEngine.UI;

public class SettingPanel : BasePanel
{
    public Button closeButton;
    public Button mainButton;

    [Header("礼品码")]
    public float okTimer = 1f;
    public float okStopTimer = 1f;
    public Button okButton;
    public InputField inputField;

    public override void OnClose()
    {
        base.OnClose();
    }

    public override void OnInit()
    {
        base.OnInit();
        path="UI/Panel/SettingPanel";
        type=PanelType.Panel;

        GameManager.Instance.canOprate=false;
    }

    public override void OnShow(params object[] par)
    {
        base.OnShow(par);
        closeButton=item.transform.Find("Close").GetComponent<Button>();
        mainButton=item.transform.Find("Main").GetComponent<Button>();
        okButton=item.transform.Find("GiftCode/OK").GetComponent<Button>();
        inputField=item.transform.Find("GiftCode").GetComponent<InputField>();

        closeButton.onClick.AddListener(CloseButton);
        mainButton.onClick.AddListener(MainButton);
        okButton.onClick.AddListener(OKButton);
    }
    private void Update()
    {
        if(okTimer>0)
        {
            okTimer-=Time.deltaTime;
        }
    }
    public void CloseButton()
    {
        GameManager.Instance.canOprate=true;
        Close();
        AudManager.instance.PlayUIAud(AudManager.instance.uiDic["点击"], 1f);
    }
    public void MainButton()
    {
        Close();
        //保存所有数据
        SaveManager.instance.SaveAllData();
        AudManager.instance.PlayUIAud(AudManager.instance.uiDic["点击"], 1f);
        //打开主页panel,关闭GamePanel,场景
        PanelManager.Open<BlackPanel>(false, false, 0, false, 3);
    }
    public void OKButton()
    {
        if(okTimer<=0)
        {
            //获取字符
            string str = inputField.text;

            GiftCode.instance.MathCode(str);
            okTimer=okStopTimer;
            inputField.text="";
        }
    }
}